package cn.iocoder.yudao.adminserver.modules.fi.dal.mysql.statistics;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.poi.ss.formula.functions.T;

import java.util.Map;

/**
 * 统计信息 Mapper
 * @author       : zhanggy
 * @date         : 2021/9/18 21:30
 * @team         : hickteam
 * @copyright    : Sysware Technology Co., Ltd
 **/
@Mapper
public interface StatisticsMapper extends BaseMapperX<Map> {
    static final String PROJECT_STATISTICS_SQL = "select * from (SELECT\n" +
            "	p.project_name AS \"projectName\",\n" +
            "	p.id AS \"projectId\",\n" +
            "	count( t.id ) AS \"itemCount\",\n" +
            "	u.nickname AS \"directorName\" \n" +
            "FROM\n" +
            "	fi_core_project p\n" +
            "	LEFT JOIN fi_core_task t ON p.id = t.project_id \n" +
            "	AND t.deleted = 0\n" +
            "	LEFT JOIN sys_user u ON u.id = p.director_uid ${ew.customSqlSegment}\n" +
            "GROUP BY\n" +
            "	p.id ORDER BY p.update_time DESC) tt";
    @Select(PROJECT_STATISTICS_SQL)
    IPage<Map> selectMapsPage(Page<Map> reqVO, @Param("ew") Wrapper<T> queryWrapper);
}
